package part3.c19_emp.service;

import part3.c19_emp.dao.GPayrollDatabase;
import part3.c19_emp.dao.PayrollDatabase;
import part3.c19_emp.employee.Employee;
import part3.c19_emp.payment_classification.PaymentClassification;
import part3.c19_emp.payment_method.HoldMethod;
import part3.c19_emp.payment_method.PaymentMethod;
import part3.c19_emp.payment_schedule.PaymentSchedule;

/**
 * Created by lie on 2018/3/29.
 */
public abstract class AddEmployeeTransaction implements Transaction {
    protected int empId;
    protected String itsAddress;
    protected String itsName;

    abstract PaymentClassification getClassification();
    abstract PaymentSchedule getSchedule();

    public AddEmployeeTransaction(int empId, String itsAddress, String itsName) {
        this.empId = empId;
        this.itsAddress = itsAddress;
        this.itsName = itsName;
    }

    private void addEmployeeTransaction(){
        PaymentClassification pc = getClassification();
        PaymentSchedule ps = getSchedule();
        //默认是出纳保管
        PaymentMethod pm = new HoldMethod();

        Employee e = new Employee(this.empId, itsAddress, itsName);
        e.setPaymentClassification(pc);
        e.setPaymentMethod(pm);
        e.setPaymentSchedule(ps);

        // TODO: 2018/3/29 模拟数据库
        GPayrollDatabase database = new GPayrollDatabase();
        database.addEmployee(empId, e);
    }

    public void Execute() {
        this.addEmployeeTransaction();
    }
}
